Ex005, ComboBox


ComboBox is similar to ListBox except that ComboBox has Edit box, so that you can
enter new item from keyboard or select already existing items by selecting from drop-down
list.

Exercise 005: ComboBox

1. Drop two ComboBox, clear their text property, name first one 'cbFontName' and
the other
'cbFontSize'.
2. Drop a label, name it 'laFontTest', write 'Font test' on it's Caption.
3. Drop a button, and write
'&Color' on it's Caption.
4. Drop a
ColorDialg.
5. Write this code on form's
OnCreate event (Don't forget to delete OnCreate begin keyword
befor pasting this code):

var
Counter: Byte;
begin
cbFontName.Items:= Screen.Fonts;
for Counter:= 4 to 32 do
 
cbFontSize.Items.Add(IntToStr(Counter*2));

6. Write this code on
cbFontSize combo box's OnClick event:

 laFontTest.Font.Size:=
  StrToInt(cbFontSize.Text);

7. Write this code on
cbFontName combo box's OnClick event:

 laFontTest.Font.Name:= cbFontName.Text;

8. Write this code on Button's OnClick event:

 if ColorDialog1.Execute then
  laFontTest.Font.Color:=
    ColorDialog1.Color;

9. Run the program and test it by selecting different font name, size, and color
using combo boxes and color button.

Notes:

- ComboBox has a Text property which represents user entry same like TEditBox, or
item selected from drop-down list.

-
Screen is a global object which encapsulate some of user interface properties
and methods.
Screen.Fonts is a TStringList in which all system fonts are listed.

- Assigning two StringLists copies all list items from a list to another such as:

cbFontName.
Items:= Screen.Fonts;